package com.example.springboot.controller;

/*
 * 功能：审批界面
 * 日期：2024-5-9 20:20
 * 作者：RabbitQ
 */

import com.example.springboot.common.Result;
import com.example.springboot.entity.Approve;
import com.example.springboot.service.ApproveService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
public class ApproveController {

    @Resource
    ApproveService approveService;


    //审批界面——选择所有审批数据
    @GetMapping("/approve/selectAllApprove")
    public Result selectAllApprove(){

        List<Approve> approveList = new ArrayList<>();

        approveList = approveService.selectAllApprove();

        return Result.success(approveList);
    }

    //审批界面——更新签名图url——通过数据的id
    @PostMapping("/approve/updateSignPic")
    public Result updateSignPic(@RequestBody Approve approve){

        approveService.updateUrlByID(approve);

        return Result.success();
    }

    //审批界面——更新审批状态——通过数据的id
    @PostMapping("/approve/updateStatus")
    public Result updateStatus(@RequestBody Approve approve){
        //1.更新状态updateStatusByID
        approveService.updateStatusByID(approve);

        return Result.success();
    }

    //审批界面——撤销审批——通过数据的id
    @PostMapping("/approve/deleteApprove")
    public Result deleteApprove(@RequestBody Approve approve){
        //1.撤销审批updateStatusByID
        approveService.deleteApproveByID(approve);

        return Result.success();
    }


    //审批界面——通过负责人和状态进行筛选
    @GetMapping("/approve/selectByChargerStatus")
    public Result selectByChargerStatus(@RequestParam String charger,
                                        @RequestParam String status){

        List<Approve> selectedApprove = approveService.selectByChargerStatus(charger, status);

        return Result.success(selectedApprove);

    }


}
